package cn.swu.homework1

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.pedromassango.delyo.R
import com.pedromassango.delyo.ui.gives.Gives


class FoodAdapter(val food: ArrayList<Food>):RecyclerView.Adapter<FoodAdapter.FoodviewHolder>()
{
    inner class FoodviewHolder(itemView: View):RecyclerView.ViewHolder(itemView)
    {
        val name =itemView.findViewById<TextView>(R.id.title)
        val description=itemView.findViewById<TextView>(R.id.desc)
        val picture=itemView.findViewById<ImageView>(R.id.image)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FoodviewHolder {
        val view=LayoutInflater.from(parent.context).inflate(R.layout.activity_food,parent,false)
        val holder=FoodviewHolder(view)
        return holder
    }

    override fun onBindViewHolder(holder: FoodviewHolder, position: Int) {
      val food=food[position]
        holder.name.text=food.name
        holder.description.text=food.description
        holder.picture.setImageResource(food.picture)
    }

    override fun getItemCount(): Int {
       return food.size
    }
}
